﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CMS.BLL;


public partial class Controls_Adv_ctrADV_Left : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitData();
            BindData();
        }
    }

    private void InitData()
    {
        int nCurrentLang = Support.GetCurrentLanguage();
        lblADV.Text = MultipleLanguage.GALLERIES [nCurrentLang - 1];
    }

    private void BindData()
    {
        int nPageCount = 0;
        Adv objAdv = new Adv();
        DataTable dtbAdv = new DataTable();
        dtbAdv = objAdv.Search(7, "", 1, -1, EnumeType.ACTIVE, 1, 7, ref nPageCount);
        rptAdv.DataSource = dtbAdv;
        rptAdv.DataBind();

    }

    protected void rptAdv_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            ImageButton btnImage = (ImageButton)e.Item.FindControl("btnImage");
            Literal ltrFlash = (Literal)e.Item.FindControl("ltrFlash");

            switch (ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "AdvTypeID")))
            {
                case 1:
                    btnImage.ImageUrl = Config.ROOT + Config.IMAGE_ADV_DEFAULT_UPLOAD + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "AdvFile"));
                    btnImage.ToolTip = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "PartnerName"));
                    btnImage.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "AdvID"));
                    break;
                case 2:
                    string sFileName = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "AdvFile"));
                    ltrFlash.Text = Pages.FrontEnds.sPreFlash + sFileName + Pages.FrontEnds.sMidFlash + sFileName + Pages.FrontEnds.sSufFlash;
                    btnImage.Visible = false;
                    break;
            }
        }

    }

    protected void rptAdv_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        string strCommand = e.CommandName;
        int nID = ConvertData.ConvertToInt(e.CommandArgument);
        Adv objAdv = new Adv();
        objAdv.LoadById(nID);
        switch (strCommand)
        {
            case "image":

                string sDetail = "http://" + objAdv.Data.AdvURL;
                Response.Redirect(sDetail);
                break;
        }
    }
}